	<?php
	session_start();
	if(!session_is_registered(myusername)){
	//header("location:index.html");
	$name = $_SESSION['name'];
	$rusername = $_SESSION['username'];
	
	}
	?>			<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
				<html>
				<head>
				</head>
				<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
				<title>Images already diagnosed</title>
				
				<!--creates cookie called 'imagePath' to store location of image. expires at end of session-->
				<script>
				function setCookie(urlParam){
				var url= urlParam.toString();
				var query_string = url.split("?");
				var param_item = query_string[1].split("=");
				
				
				document.cookie = 'imagePath='+param_item[1]+';'
				}
				
				</script>
				
				<body>	
<?php
	include "config.php";
				
	$image_query = "SELECT * FROM images";
	$image_result = mysql_query($image_query);
	echo "<h3>There are ". mysql_num_rows($image_result) ." images with diagnoses to be rated.</h3>";
	$index=0;
	$image_previous_row_id=-1;
	echo "<table border=1>";
	while($image_row = mysql_fetch_array($image_result))
	{echo "<tr>";	
		$imagepath = $image_row[file_path];
		$annotation_query = "SELECT * FROM annotations WHERE image_id =".$image_row[id];
		$annotation_result = mysql_query($annotation_query);

		while($annotation_row = mysql_fetch_array($annotation_result))
		{
			$user_query = "SELECT * from users";
			$user_result = mysql_query($user_query);
			
			while($user_row = mysql_fetch_array($user_result))
			{
				if($user_row[id] == $annotation_row[user_id])
				{
				if ($image_previous_row_id != $image_row[id])
					{
					$totalup = $annotation_row[votes_up]; //not same img as previous annotation, reset to current
					$totaldown = $annotation_row[votes_down]; //not same img as previous annotation, reset to current
					$user = $user_row[username];

					$annotationpath = $annotation_row[file_path];
					$annotationId = $annotation_row[id];
					$imagepath=$image_row[file_path];
					$combinedannotation = "view_image.php?path=".$imagepath;									//if (($totalup !=0)&&($totaldown !=0)){
					//echo 	"<td><a href='".$combinedannotation."'>".$imagepath."<br/><object id='$annotationId' type='image/svg+xml' data=".$annotationpath."></object></a><br/>";
					echo 	"<td><a href='".$combinedannotation."'>".$imagepath."<br/><img src='".$imagepath."' height=240 height=320/></a><br/>";
					

					$totalup = $annotation_row[votes_up];
					$totaldown = $annotation_row[votes_down];
					echo $user." - up: ".$totalup." down: ".$totaldown."</td>";
					}
					//$image_previous_row_id = $image_row[id];
				}
				//break;
			}
		}
		echo "</tr>";
	}
				
		echo "</table>";
		if (mysql_num_rows($image_result) == 0) {
		echo "<h3>No images to be diagnosed. Click <a href='welcome.php'>here</a> to go back</h3>";
		}
		mysql_close($con);
		?>
</body>
</html>
	
